//
//  HomeTopCell.m
//  yunyan
//
//  Created by haichuang on 2018/3/23.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "HomeTopCell.h"

@implementation HomeTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createTopCell];
        
    }
    return self;
}

-(void)createTopCell{
    
    WeakSelf;
    //滚动的 banner
//    _topScrollerview = [[UIImageView alloc]init];
//    [self addSubview:_topScrollerview];
//    [_topScrollerview mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo (weakSelf.mas_left).offset (10.0f);
//        make.right.right.equalTo (weakSelf.mas_right).offset (-10.0f);
//        make.top.equalTo (@(6));
//        make.height.equalTo (@(ScreenWidth*7/15));
//    }];
//
//    BannerScrollViewTime *banner = [[BannerScrollViewTime alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth*7/15) with:@"img"];
//
//        if (@available(iOS 11.0, *)) {
//            banner.scroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//        } else {
//            self.automaticallyAdjustsScrollViewInsets = NO;
//        }
    //此处是为了展示demo效果 做的假数据 之后以后台返回为准
//      _bannerArr = @[@"1",@"1",@"1"];
//     _bannerArr = USER_DEFAULTGet(@"bannerArr");
//    
//         [banner setPicData:_bannerArr];
//        [_topScrollerview addSubview:banner];
    
    
    NSArray * _bannerArr = USER_DEFAULTGet(@"bannerArr");
    UIView * topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, ScreenWidth*7/15)];
    topView.backgroundColor =[UIColor groupTableViewBackgroundColor];
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WIDTH, ScreenWidth*7/15) delegate:self placeholderImage:[UIImage imageNamed:@"img_2"]];
    cycleScrollView.backgroundColor = [UIColor whiteColor] ;
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    //        cycleScrollView.currentPageDotColor = NavBackColor;
    cycleScrollView.imageURLStringsGroup = _bannerArr;
    [topView addSubview:cycleScrollView];
    cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
        
        
    };
    [topView addSubview:cycleScrollView];
    [self addSubview:topView];
 

    //中间的分类:知、行、合、一
    UIView * minView = [[UIView alloc]init];
    minView.frame = CGRectMake(0,ScreenWidth*7/15+9.f , ScreenWidth, 70);
    [self addSubview:minView];
//    [minView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo (weakSelf);
////        make.top.equalTo (_topScrollerview.mas_bottom).offset (9.f);
//        make.top.equalTo (@ScreenWidth*7/15+9.f);
//        make.height.equalTo (@(70));
//    }];
  
    
    CGFloat width = ScreenWidth/4;
    CGFloat btnWidth = width -20;
 
    _lableArr = USER_DEFAULTGet(@"className");
    _imageArr = USER_DEFAULTGet(@"classimage");
  
    
    for (int i = 0; i < _lableArr.count; i ++) {
        
//        _optionView = [[OptionButton alloc]initWithFrame:CGRectMake(width * i, 0, width, 70)];
//        [minView addSubview:_optionView];
////        [_optionView.button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",@"home_list_new"]] forState:UIControlStateNormal];
//
//        [_optionView.button sd_setBackgroundImageWithURL:ImageUrl(_imageArr[i]) forState:UIControlStateNormal];
//        _optionView.titleLabel.text = _lableArr[i];
//        _optionView.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:15];
//        _optionView.titleLabel.textColor = RGBA(51, 51, 51, 1);
//        _optionView.titleLabel.textColor = RGBA(51, 51, 51, 1);
//        _optionView.button.tag = 1000 +i;
//        [_optionView.button addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(btnWidth * i + 20*i +10, 0, btnWidth, 50);
        [btn sd_setBackgroundImageWithURL:ImageUrl(_imageArr[i]) forState:UIControlStateNormal];
       [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 1000 +i;
        [minView addSubview:btn];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(width*i, 60, width, 20)];
        label.text = _lableArr[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:14];
        label.textColor = RGBA(51, 51, 51, 1);
        label.textColor = RGBA(51, 51, 51, 1);
        [minView addSubview:label];
    }
    
    
    
}

-(void)btnClicked:(UIButton *)sender{
    
   _categoryTitle = self.lableArr[sender.tag-1000];
    //此处可根据以后返回的数据 做一下switch 的提炼
//    switch (sender.tag) {
//        case 1000:
//
//            _categoryTitle = @"时政要闻";
//            break;
//            
//        case 1001:
//
//            _categoryTitle = @"爱上云岩";
//            break;
//            
//        case 1002:
//
//          _categoryTitle = @"志同道合";
//            break;
//            
//        case 1003:
//           _categoryTitle = @"文以载道";
//            break;
//            
//        default:
//            break;
//    }
    
    if (_categoryBlock) {
        
        _categoryBlock (_categoryTitle);
    }
    
}




@end
